package com.piece.core.mongo.service;

import com.piece.core.framework.support.bootstrap.DataTable;
import com.piece.core.framework.support.bootstrap.QueryTable;
import com.piece.core.mongo.entity.MongoBeanPostLog;
import com.piece.core.mongo.repository.MongoBeanPostLogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Transactional
@Service(value = "mongoBeanPostLogService")
public class MongoBeanPostLogService {

    @Autowired
    private MongoBeanPostLogRepository mongoBeanPostLogRepository;

    public MongoBeanPostLog insert(MongoBeanPostLog log) {
        return mongoBeanPostLogRepository.save(log);
    }

    public MongoBeanPostLog update(MongoBeanPostLog log) {
        return mongoBeanPostLogRepository.saveOrUpdate(log.getLogId(), log);
    }

    public void delete(String logId) {
        MongoBeanPostLog log = new MongoBeanPostLog();
        log.setLogId(logId);
        mongoBeanPostLogRepository.delete(log);
    }

    public void deleteByClientId(String clientId) {
        MongoBeanPostLog log = new MongoBeanPostLog();
        log.setClientId(clientId);
        mongoBeanPostLogRepository.delete(log);
    }

    public void deleteAll() {
        mongoBeanPostLogRepository.deleteAll();
    }

    public List<MongoBeanPostLog> findList(QueryTable queryTable) {
        return mongoBeanPostLogRepository.find(queryTable);
    }

    public DataTable findPage(QueryTable queryTable) {
        return mongoBeanPostLogRepository.findPage(queryTable);
    }
}